package com.newegg.datafeed.adserving.adwords;

import java.rmi.RemoteException;
import com.google.api.ads.adwords.axis.v201809.cm.ApiException;
import com.google.api.ads.adwords.axis.v201809.cm.Operator;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomer;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerOperation;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerReturnValue;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerServiceInterface;
import com.google.api.ads.common.lib.exception.ValidationException;

public class AccountService extends ADWordsParent{
	
	ManagedCustomerServiceInterface accountService;
	
	public AccountService() throws ValidationException {
		accountService = adWordsServices.get(defaultSession, ManagedCustomerServiceInterface.class);
	}
	
	public Long createCustomer(String name, String currencyCode, String datetimezone) throws ApiException, RemoteException {
		ManagedCustomer customer = new ManagedCustomer();
	    customer.setName(name);
	    customer.setCurrencyCode(currencyCode);
	    customer.setDateTimeZone(datetimezone);
	    ManagedCustomerOperation operation = new ManagedCustomerOperation();
	    operation.setOperand(customer);
	    operation.setOperator(Operator.ADD);
	    ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] {operation};
	    ManagedCustomerReturnValue result = accountService.mutate(operations);
	    ManagedCustomer newCustomer = result.getValue(0);
	    return newCustomer.getCustomerId();
	}
	
}
